﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace Face.Web.login_and_signup
{
    public partial class CheckImage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string RandCharString = "0123456789";
                string randString = "";
                Random random = new Random();
                do
                {
                    //使用DateTime.Now.Millisecond作为生成随机数的参数，增加随机性
                    randString += RandCharString.Substring(random.Next(DateTime.Now.Millisecond) % RandCharString.Length, 1);
                }
                while (randString.Length < 4);
                RandImage randImage = new RandImage();
                System.Drawing.Image image = randImage.GetImage(randString);
                Session["randString"] = randString;
                System.IO.MemoryStream memoryStream = new MemoryStream();
                image.Save(memoryStream, ImageFormat.Jpeg);
                Response.ClearContent();
                Response.ContentType = "image/gif";
                Response.BinaryWrite(memoryStream.ToArray());
                image.Dispose();
                Response.End();
            }

        }
    }
}